{% extends "stocksys/base/base_page.html" %}
{% load staticfiles %}
{% block content %}
    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-8">
                    <div class="card" id="profile-main">
                        <div class="content">
                            <h3>你好啊 {{ user.username }}</h3>
                            <div class="nav-tabs-navigation">
                                <div class="nav-tabs-wrapper">
                                    <ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
                                        <li class="active">
                                            <a href="#profile11" aria-controls="profile11" role="tab" data-toggle="tab">信息</a>
                                        </li>
                                        <li>
                                            <a href="#activities11" aria-controls="messages11" role="tab"
                                               data-toggle="tab">近期操作</a>
                                        </li>
                                        <li>
                                            <a href="#settings11" aria-controls="settings11" role="tab"
                                               data-toggle="tab">设置</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                            <div class="tab-content">
                                <div role="tabpanel" class="tab-pane active" id="profile11">
                                    <p>这个人很懒，啥都没有写哦</p>
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <div class="p-15">
                                                <h4>信息</h4>
                                                <hr>
                                                <div class="row m-l-5">
                                                    <div class="col-sm-6 p-5">
                                                        <p><strong>上次登录时间</strong></p>
                                                        <p><strong>上次登录IP</strong></p>
                                                        <p><strong>上次登录地址</strong></p>
                                                        <p><strong>加入时间</strong></p>
                                                        <p><strong>用户等级</strong></p>
                                                    </div>
                                                    <div class="col-sm-6 p-10 p-5">
                                                        <p>{{ user.last_login | date:'Y-m-d H:i:s' }}</p>
                                                        <p>{{ sysconf.login_ip_address }}</p>
                                                        <p>{{ sysconf.login_ip_city }}</p>
                                                        <p>{{ user.date_joined | date:'Y-m-d H:i:s' }}</p>
                                                        {% if user.is_superuser %}
                                                            <p>超级用户</p>
                                                        {% else %}
                                                            <p>普通用户</p>
                                                        {% endif %}
                                                    </div>
                                                </div>
                                                <h4>联系方式</h4>
                                                <hr>
                                                <div class="row">
                                                    <div class="col-sm-6">
                                                        <p><i class="zmdi zmdi-email"></i>Email</p>
                                                    </div>
                                                    <div class="col-sm-6 p-10">
                                                        <p>{{ user.email }}</p>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                                <div role="tabpanel" class="tab-pane" id="activities11">
                                    <div class="widget p-25">
                                        <div class="widget-body">
                                            <div class="streamline sl-style-2">
                                                <div class="sl-item sl-primary">
                                                    <div class="sl-content">
                                                        <small class="text-muted">5 mins ago</small>
                                                        <p>Williams has just joined Project X</p>
                                                    </div>
                                                </div>
                                                <div class="sl-item sl-danger">
                                                    <div class="sl-content">
                                                        <small class="text-muted">25 mins ago</small>
                                                        <p>Jane sent you a request to grant access to the project
                                                            folder</p>
                                                    </div>
                                                </div>
                                                <div class="sl-item sl-success">
                                                    <div class="sl-content">
                                                        <small class="text-muted">40 mins ago</small>
                                                        <p>Kate added you to her team</p>
                                                    </div>
                                                </div>
                                                <div class="sl-item">
                                                    <div class="sl-content">
                                                        <small class="text-muted">55</small>
                                                        <p>John has finished his task</p>
                                                    </div>
                                                </div>
                                                <div class="sl-item sl-warning">
                                                    <div class="sl-content">
                                                        <small class="text-muted">60 mins ago</small>
                                                        <p>Jim shared a folder with you</p>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div role="tabpanel" class="tab-pane" id="settings11">
                                    <div class="widget p-25">
                                        <div class="widget-body">
                                            <form id="user_config">
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">我的资金</label>
                                                    <input name="my_capital" class="form-control"
                                                           value="{{ sysconf.my_capital }}"
                                                           type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 label-control">回测开始时间</label>
                                                    <input name="predict_start_time" class="form-control datepicker"
                                                           value="{{ sysconf.predict_start_time | date:'Y-m-d' }}"
                                                           type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 label-control">回测结束时间</label>
                                                    <input name="predict_end_time" type="text"
                                                           class="form-control datepicker"
                                                           value="{{ sysconf.predict_end_time | date:'Y-m-d' }}">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">主模型</label>
                                                    <select name="main_model" class="form-control">
                                                        {% for t_model in models %}
                                                            {% if t_model.name == model.name %}
                                                                <option selected>{{ model.name }}</option>
                                                            {% else %}
                                                                <option>{{ t_model.name }}</option>
                                                            {% endif %}
                                                        {% endfor %}
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">主规则</label>
                                                    <div class="select">
                                                        <select name="main_rule" class="form-control">
                                                            {% for t_rule in rules %}
                                                                {% if t_rule.name_en == rule.name_en %}
                                                                    <option selected>{{ t_rule.name_en }}</option>
                                                                {% else %}
                                                                    <option>{{ t_rule.name_en }}</option>
                                                                {% endif %}

                                                            {% endfor %}
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">深圳交易所税率%</label>
                                                    <input name="sz_price" class="form-control"
                                                           value="{{ sysconf.sz_price }}"
                                                           type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">深圳交易所最低税</label>
                                                    <input name="sz_min_price" class="form-control"
                                                           value="{{ sysconf.sz_min_price }}"
                                                           type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">上海交易所税率%</label>
                                                    <input name="sh_price" class="form-control"
                                                           value="{{ sysconf.sh_price }}"
                                                           type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">上海交易所最低税</label>
                                                    <input name="sh_min_price" class="form-control"
                                                           value="{{ sysconf.sh_min_price }}"
                                                           type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">印花税%</label>
                                                    <input name="stamp_tax" class="form-control"
                                                           value="{{ sysconf.stamp_tax }}"
                                                           type="text">
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-4 control-label">过户费%</label>
                                                    <input name="transfer_feed" class="form-control"
                                                           value="{{ sysconf.stamp_tax }}"
                                                           type="text">
                                                </div>
                                                <div class="row">
                                                    <div class="card-footer text-center">
                                                        <button type="submit" class="btn btn-info btn-fill">保存</button>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card card-user">
                        <div class="author">
                            <a href="#pablo">
                                <img class="img avatar"
                                     src="https://oscimg.oschina.net/oscnet/up-9k5ar9dbgcypmqmfio22xsfecvkpdmcc.jpg!/both/200x200?t=1569270362000"/>
                            </a>
                        </div>
                        <div class="content">
                            <h6 class="category text-gray">Engineer</h6>
                            <h4 class="title">{{ user.username }}</h4>
                            <p class="description">
                                菜是原罪你知道吗？
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block pagescript %}
    <script>
        $('#user_config').validate({
            debug: false,
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    url: "{% url 'stocksys:user_settings' %}",
                    headers: {'X-CSRFToken': $.cookie('csrftoken')},
                    dataType: "json",
                    type: "CONFIG",
                    success: function (data) {
                        if (data['status'] === 200) {
                            swal({
                                title: "保存成功",
                                text: "成功保存配置文件",
                                buttonsStyling: false,
                                confirmButtonClass: "btn btn-success",
                                type: "success"
                            }).catch(swal.noop);
                        } else {
                            swal({
                                title: "保存失败",
                                text: data['info'],
                                buttonsStyling: false,
                                confirmButtonClass: "btn btn-success",
                                type: "success"
                            }).catch(swal.noop);
                        }
                    },
                    error: function (e) {
                        console.log(e);
                    }
                });
            }
        })
    </script>
{% endblock %}

